package cn.com.sina.finance.todolist.util;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.Toast;

/**
 * @author yuebo
 * @date 2024/10/10
 */
public class ToastUtil {

    public static void showLongToast(Context context, String msg) {
        if (context == null || TextUtils.isEmpty(msg)) {
            return;
        }
        Looper looper = Looper.myLooper();
        Looper mainLooper = Looper.getMainLooper();
        if (looper == mainLooper) {
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
        } else {
            new Handler(mainLooper).post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                }
            });
        }
    }
}
